package net.bcxuexi.pool;

import net.bcxuexi.tools.MyLog;

/**
 * 先进先出调度
 */
public class FIFODispatcher extends Dispatcher {

	public FIFODispatcher(int corePoolSize, int maximumPoolSize){
		super(corePoolSize, maximumPoolSize);
	}
	@Override
	public synchronized void dispatch() {
		Runnable r = null;// 被执行的任务

		if (r == null) {
			try {
				r = take();// 从阻塞队列中取任务，可能会被阻塞
			} catch (InterruptedException e) {
				// 没有取到任务
				return;
			}
		}
		
		if (r == null) {
			MyLog.info("调度任务为空，休息！");
			return;
		}
		try {
			threadPool.executeBlock(r);

		} catch (InterruptedException e) {

		}

		try {
			sleep(80);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

	}

}
